<template>
  <div>
    <Button type="primary" @click="openGoban()">打开棋谱</Button>
    <RadioGroup v-model="hint" @on-change="stepControl()">
      <Radio label="step">
        <Icon type="ios-funnel"/>
        <span>落子提醒</span>
      </Radio>
      <Radio label="currentStep">
        <Icon type="md-hand"/>

        <span>当前手数</span>
      </Radio>
      <Radio label="hands">
        <Icon type="ios-hand"/>
        <span>全部手数</span>
      </Radio>
    </RadioGroup>
    <Button type="primary" @click="openGoban('begin')">{{ begin }}</Button>
    <Button type="primary" @click="openGoban('fback')">{{ fback }}</Button>
    <Button type="primary" @click="openGoban('back')">{{ back }}</Button>
    <Button type="primary" @click="openGoban('step')">{{ step }}</Button>
    <Button type="primary" @click="openGoban('fstep')">{{ fstep }}</Button>
    <Button type="primary" @click="openGoban('end')">{{ end }}</Button>
    <Button type="primary" @click="analyze()">引擎分析</Button>
    <Button type="info" @click="setup()">修改配置</Button>
    <Button type="success" disabled @click="saveGoban()">保存对局信息</Button>
    <Button type="info" @click="boardAnalyze()">形式判断</Button>
    <Button type="info" @click="sgfModal = true;sgfText='';">导入棋谱</Button>
    <Modal
        v-model="sgfModal"
        title="导入棋谱"
        @on-ok="ok"
        @on-cancel="cancel">
      <Tabs value="sgfText">
        <TabPane label="导入sgf文本" name="sgfText">
          <Input v-model="sgfText" type="textarea" :rows="4" placeholder="在此处粘贴SGF"/>
        </TabPane>
        <TabPane label="导入sgf棋谱文件" name="sgfFile" disabled="">

        </TabPane>

      </Tabs>
    </Modal>
  </div>
</template>

<script>
//下方的工具栏
import Bus from "emitvue";
import * as util from './util.js'

export default {
  data() {
    return {
      hint: "step", //枚举 step 是当前落子,currentStep是当前手数，hands是展示所有的,手数
      begin: "|<",
      end: ">|",
      step: ">",
      back: "<",
      fstep: ">>",
      fback: "<<",
      sgfModal: false,
      sgfText: '',
    };
  },
  methods: {
    //打开棋谱
    openGoban() {
    },
    //对局控制
    stepControl() {
      Bus.$emit("stepControl", this.hint);
    },
    analyze() {
      Bus.$emit("analyze", null);
    },
    setup() {
      Bus.$emit("setup", null);
    },
    saveGoban() {
      Bus.$emit("saveGoban", null);
    },
    //局面分析
    boardAnalyze() {
      Bus.$emit("boardAnalyze", null);
    },
    // 点击ok导入棋谱
    ok() {
      if (this.sgfText === '') {
        this.$Message.warning("检测到棋谱为空，取消导入")
        return
      }
      let res = util.parseSgf(this.sgfText)
      Bus.$emit("addSgf", res);
      this.$Message.info('导入成功');

    },
    cancel() {
      this.$Message.info('取消导入');
    }

  },
  created() {
  },
};
</script>

<style>
</style>